<?php

/**
 * Created by PhpStorm.
 * User: wukent
 * Date: 2017/9/20
 * Time: 上午9:46
 */
class DetailsAction extends ApiAction
{

    protected $mainMod;
    protected $commentMod;
    protected $commentphotoMOD;
    protected $merchantphotoMod;
    protected function _initialize() {
        parent::_initialize();
        $this->mainMod = D("Merchant");
        $this->commentMod = D("MerchantComment");
        $this->commentphotoMOD = D("MerchantCommentPhoto");
        $this->merchantphotoMod = D("MerchantPhoto");
    }

    public function show(){

        $merchant_id = empty($_POST['merchant_id'])?0:$_POST['merchant_id'];

        if ($merchant_id>0){
            $pitch = $this->mainMod->getInfo($merchant_id);

            if ($pitch){

                $pitch['province_name'] = D('Province')->getInfo($pitch['province_id']);
                $pitch['city_name'] = D('City')->getInfo($pitch['city_id']);
                $pitch['area_name'] = D('Area')->getInfo($pitch['area_id']);
                $pitch['photo_num'] = $this->merchantphotoMod->getCount($merchant_id);
                $pitch['commentlist'] = $this->commentMod->num($merchant_id,1,5);
                foreach ($pitch['commentlist'] as $key=>$value){
                    $pitch['commentlist'][$key]['photolist'] = $this->commentphotoMOD->getList($value['comment_id']);
                }
                $pitch['comment_num'] = count($pitch['commentlist']);

                $this->rest($pitch,1);
            }else{
                $this->rest('',17);
            }



        }else {
            $this->rest('',16);

        }

    }

    public function photolist(){
        $merchant_id = empty($_POST['merchant_id'])?0:$_POST['merchant_id'];
        $page = empty($_POST['curpage'])?1:$_POST['curpage'];
        $pernum = empty($_POST['cursize'])?6:$_POST['cursize'];
        if ($merchant_id>0){
            $list = $this->merchantphotoMod->getList($merchant_id,$page,$pernum);
            if (count($list)>0){
                $this->rest($list,1);
            }else{
                $this->rest('',17);
            }

        }else{
            $this->rest('',16);
        }

    }

}